var e = require('../@babel/runtime/helpers/objectSpread2.js'),
  t = require('1E1DDD9770B67DCF787BB59075001B27.js'),
  a = (t.baseUrl, t.systemType),
  r = {
    buriedPoint: 'post /api/v1/guest/page/access',
    goodsPoint: 'post /api/v1/guest/goods/bury',
    sharePoint: 'post /api/v1/guest/share/action',
  },
  o = {
    'pages/index/index': 'index',
    'pages/goodsDetail/goodsDetail': 'goods_detail',
    'pages/submitOrder/submitOrder': 'order_conform',
    'pages/Order/orderPay/orderPay': 'order_pay',
  },
  n = [],
  s = +new Date();
function i(t) {
  var i = this,
    d = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {},
    g = arguments.length > 3 && void 0 !== arguments[3] ? arguments[3] : {},
    c = wx.getStorageSync('accessToken'),
    l = wx.getStorageSync('user');
  if (!c || !l)
    return console.log('没有token或者没有用户信息'), Promise.reject();
  var u = wx.getStorageSync('initSystem');
  return u
    ? 1 != +u.is_open_stat
      ? (console.log('没有打开统计'), Promise.reject())
      : new Promise(function (c, l) {
          var p = e(
            {
              'X-Auth-Token': wx.getStorageSync('accessToken'),
              'X-From': 'wzg_c',
            },
            g.headers,
          );
          delete g.headers;
          var y = t.split(' ');
          1 === y.length && y.unshift('get'),
            (d.systemType = a),
            i.route && (d.page = o[i.route]),
            (d.platform_type = 'mp');
          var m = wx.getStorageSync('user');
          m &&
            ((d.user = m.member.id),
            (d.user_type = m.member.type),
            (d.is_new = m.member.is_new),
            (d.user_id = m.member.id));
          var S = getApp();
          if (
            (S.globalData.rid && (d.share_user = S.globalData.rid),
            S.globalData.rtype && (d.share_user_type = S.globalData.rtype),
            'order_pay' === d.page && (d.order_id = i.data.order_id),
            t === r._buriedPoint)
          ) {
            if (
              ('in' === d.action_type
                ? ((d.entered_at = parseInt(+new Date() / 1e3)), (n = [d]))
                : 1 === n.length
                  ? ((d.left_at = parseInt(+new Date() / 1e3)), n.push(d))
                  : (console.log('没有开始点,丢弃统计内容'), (n = [])),
              2 === n.length)
            ) {
              var _ = e(e({}, n[0]), n[1]);
              if ((delete _.action_type, _.entered_at && _.left_at)) {
                var h = wx.getStorageSync('waitSendStat');
                h ? h.push(_) : (h = [_]), wx.setStorageSync('waitSendStat', h);
              } else console.log('丢弃烂数据', _);
            }
            var w = wx.getStorageSync('waitSendStat');
            if (!w || !(w.length >= 1e3 || +new Date() - s > 3e5)) return;
            (d = { systemType: a, data: w }),
              (s = +new Date()),
              wx.setStorageSync('waitSendStat', []);
          }
          wx.request(
            e(
              {
                url: ''.concat(u.stat_domain_name, '/').concat(y[1]),
                data: d,
                header: p,
                method: y[0],
                timeout: 1e3,
                success: function (e) {
                  0 != +e.data.code ? l(e.data) : c(e.data.data);
                },
                fail: function (e) {
                  l(e);
                },
              },
              g,
            ),
          );
        })
    : (console.log('没有初始化'), Promise.reject());
}
Object.keys(r).forEach(function (e) {
  (r['_'.concat(e)] = r[e]),
    (r[e] = function () {
      var t =
          arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {},
        a = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {},
        o = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : {};
      return i.call(this, r['_'.concat(e)], t, a, o);
    });
}),
  (module.exports = r);
